import storage from "./storage"
import BigNumber from 'bignumber.js'
import {
	mapMutations
} from "vuex"
/**
 * 强制登录
 * 根据token判断用户有没有登录
 */
export const ForceLogin = (step) => {
	const token = storage.getToken();
	if (!token) {
		uni.navigateTo({
			url: "/pages/moduleLogin/login/login"
		})
		return false
	}
	return true
}
/**
 * 根据用户基本信息里的身高计算步距
 * 再根据step计算行走距离
 */
export const ByStepToDistance = (step) => {
	let userInfo = storage.getUserInfo()
	let height = userInfo.height
	let bigHeight = new BigNumber(height)
	let sex = userInfo.sex
	let buju = 0
	if (height === 0) {
		buju = 0.7
	}
	if (sex === '0') {
		buju = bigHeight.multipliedBy(0.415).dividedBy(100).dp(2, BigNumber.ROUND_UP)
		buju = parseFloat(buju)
	} else if (sex === '1') {
		buju = bigHeight.multipliedBy(0.413).dividedBy(100).dp(2, BigNumber.ROUND_UP)
		buju = parseFloat(buju)
	} else {
		buju = 0.7
	}
	let distance = new BigNumber(step).multipliedBy(buju).dividedBy(1000).dp(2, BigNumber.ROUND_UP)
	return parseFloat(distance)
}
/**
 * 图表X轴标记点数量
 */
export const UChartXLabelCount = (length) => {
	console.log(length)
	let length1 = length
	let count = 0
	switch (length1) {
		case 0:
			count = 0;
			break;
		case 1:
			count = 0;
			break;
		case 2:
			count = 0;
			break;
		case 3:
			count = 0;
			break;
		case 4:
			count = 0;
			break;
		case 5:
			count = 0;
			break;
		case 6:
			count = 0;
			break;
		case 7:
			count = 0;
			break;
		case 8:
			count = 0;
			break;
		case 9:
			count = 1;
			break;
		case 10:
			count = 2;
			break;
		case 11:
			count = 1;
			break;
		case 12:
			count = 3;
			break;
		case 13:
			count = 3;
			break;
		case 14:
			count = 3;
			break;
		case 15:
			count = 3;
			break;
		case 16:
			count = 4;
			break;
		case 17:
			count = 3;
			break;
		case 18:
			count = 5;
			break;
		case 19:
			count = 5;
			break;
		case 20:
			count = 5;
			break;
		case 21:
			count = 4;
			break;
		case 22:
			count = 6;
			break;
		case 23:
			count = 5;
			break;
		case 24:
			count = 5;
			break;
		case 25:
			count = 5;
			break;
		case 26:
			count = 4;
			break;
		case 27:
			count = 6;
			break;
		case 28:
			count = 6;
			break;
		case 29:
			count = 6;
			break;
		case 30:
			count = 6;
			break;
		case 31:
			count = 5;
			break;
	}
	console.log(count)
	return count
}
